{% extends "base.html" %} {% block title %}帖子管理 - 运动健康管理系统{%
endblock %} {% block content %}
<div class="container py-5">
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item">
        <a href="{{ url_for('admin_dashboard') }}">管理员仪表盘</a>
      </li>
      <li class="breadcrumb-item active" aria-current="page">帖子管理</li>
    </ol>
  </nav>

  <h1 class="mb-4"><i class="bi bi-file-earmark-text"></i> 帖子管理</h1>

  <!-- 搜索框 -->
  <div class="row mb-4">
    <div class="col-md-6">
      <form action="{{ url_for('admin_posts') }}" method="GET" class="d-flex">
        <input
          type="text"
          name="keyword"
          class="form-control me-2"
          placeholder="搜索帖子..."
          value="{{ keyword if keyword }}" />
        <button type="submit" class="btn btn-primary">搜索</button>
      </form>
    </div>
  </div>

  <div class="card shadow">
    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-hover">
          <thead>
            <tr>
              <th>标题</th>
              <th>作者</th>
              <th>发布时间</th>
              <th>浏览量</th>
              <th>点赞数</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            {% for post in posts %}
            <tr>
              <td>
                <a
                  href="{{ url_for('post_detail', post_id=post.id) }}"
                  class="text-decoration-none">
                  {{ post.title }}
                </a>
              </td>
              <td>{{ post.user.username }}</td>
              <td>
                {{ post.created_at.strftime('%Y-%m-%d %H:%M') if post.created_at
                else '未知' }}
              </td>
              <td>{{ post.view_count }}</td>
              <td>{{ post.like_count }}</td>
              <td>
                <div class="d-flex">
                  <form
                    action="{{ url_for('delete_post', post_id=post.id) }}"
                    method="POST"
                    class="me-2"
                    onsubmit="return confirm('确定要删除这篇帖子吗？此操作不可撤销。');">
                    <button type="submit" class="btn btn-sm btn-danger">
                      删除帖子
                    </button>
                  </form>
                </div>
              </td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
{% endblock %}
